﻿Imports OpenArchive.Document

Namespace OpenArchive
    Namespace Collections
        Public Class DocComponentEnumerator
            Implements IEnumerator
            Private m_ComponentList As ComponentList
            Private m_ComponentListEnum As IEnumerator

            Friend Sub New(ByVal complist As ComponentList)
                m_ComponentList = complist
                m_ComponentListEnum = m_ComponentList.GetEnumerator
            End Sub
            Public ReadOnly Property Current() As Object Implements Global.System.Collections.IEnumerator.Current
                Get
                    Dim _keyValuePair As KeyValuePair(Of String, Components.IComponent)
                    _keyValuePair = m_ComponentListEnum.Current
                    Dim instanceNumber As Integer
                    instanceNumber = GetInstanceNrFromKey(_keyValuePair.Key)
                    Dim retval As InstanceComponentPair(Of Integer, Components.IComponent)
                    retval = New InstanceComponentPair(Of Integer, Components.IComponent)(instanceNumber, _keyValuePair.Value)

                    Return retval

                End Get
            End Property
            Public Function MoveNext() As Boolean Implements Global.System.Collections.IEnumerator.MoveNext
                Return m_ComponentListEnum.MoveNext()
            End Function

            Public Sub Reset() Implements Global.System.Collections.IEnumerator.Reset
                m_ComponentListEnum.Reset()
            End Sub
            Private Function GetInstanceNrFromKey(ByVal Key As String) As Integer
                Dim Inststr As String
                Inststr = Key.Split("."c)(0)
                Return Convert.ToInt32(Inststr)
            End Function
        End Class
    End Namespace
End Namespace
